﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Demo.Business;
using Niknak.Social.Twitter;

namespace Demo
{
    class Program
    {
        private static void ProcessTweet(object context, Niknak.Social.Twitter.Streams.Enums.StreamStatus status, IMessage twitterMessage)
        {
            if (status == Niknak.Social.Twitter.Streams.Enums.StreamStatus.OK)
                Console.WriteLine(twitterMessage.Text);
        }

        static void Main(string[] args)
        {

            //facebook likes
            //string postId = "";
            //int pageSize = 100;
            //string accessToken = "";
            //string finalCursor = null;
            //Niknak.Social.Facebook.Likes.LikesData likesData = Niknak.Social.Facebook.Likes.GetPostLikes(accessToken, postId, pageSize);

            //do
            //{
            //    foreach (KeyValuePair<string, string> user in likesData.Users)
            //        Console.WriteLine(user.Key + " " + user.Value);

            //    if (!likesData.EndOfStream)
            //        likesData = Niknak.Social.Facebook.Likes.GetPostLikes(accessToken, postId, pageSize, likesData.AfterCursor, Niknak.Social.Facebook.Likes.CursorType.After);
            //    else
            //        finalCursor = likesData.AfterCursor;
            //} while (string.IsNullOrEmpty(finalCursor));

            //Console.WriteLine("\nFinal cursor: " + finalCursor);


            //facebook comments
            //string commentsPostId = "";
            //int commentsPageSize = 10;
            //string accessToken = "";
            //string finalCursor = null;
            //Niknak.Social.Facebook.Comments.CommentsPage commentsPage = Niknak.Social.Facebook.Comments.GetPostComments(accessToken, commentsPostId, commentsPageSize);

            //do
            //{
            //    foreach (Niknak.Social.Facebook.Comments.Comment comment in commentsPage.Data)
            //        Console.WriteLine(comment.UserName + ": " + comment.Message);

            //    if (!commentsPage.EndOfStream)
            //        commentsPage = Niknak.Social.Facebook.Comments.GetPostComments(accessToken, commentsPostId, commentsPageSize, commentsPage.AfterCursor, Niknak.Social.Facebook.Comments.CursorType.After);
            //    else
            //        finalCursor = commentsPage.AfterCursor;
            //} while (string.IsNullOrEmpty(finalCursor));

            //Console.WriteLine("\nFinal cursor: " + finalCursor);


            //twitter tests

            //Console.WriteLine("Loading tweets...\n\n");

            string screenName = "SimonHoade";
            int count = 50;                     //defaults to 10
            bool includeRTs = false;            //defaults to false
            string sinceMessageId = "1";        //defaults to "1"

            ////streaming
            //using (Niknak.Social.Twitter.Streams.Public.Statuses<TwitterConfig, object> statusesStream = new Niknak.Social.Twitter.Streams.Public.Statuses<TwitterConfig, object>(ProcessTweet, null))
            //{
            //    statusesStream.FilterByKeywords<TwitterMessage, TwitterUser, TwitterMedia, TwitterMediaSize>("#nowplaying,#mayday");
            //    //statusesStream.FilterByUsers<TwitterMessage, TwitterUser, TwitterMedia, TwitterMediaSize>("1234");
            //    //statusesStream.FilterByLocations<TwitterMessage, TwitterUser, TwitterMedia, TwitterMediaSize>("-122.75,36.8,-121.75,37.8");

            //    Thread.Sleep(80000);
            //    Console.WriteLine("We're done here");
            //}


            ////search
            //List<Message> basicTweets = Search<TwitterConfig>.GetTweets
            //    (
            //        "#nowplaying",
            //        count,
            //        "mixed",
            //        sinceMessageId
            //    );

            //foreach (Message tweet in basicTweets)
            //    Console.WriteLine(tweet.Text + "\n\n");


            //basic
            List<TwitterMessage> basicTweets = UserTimeline<TwitterConfig>.GetTweets
                (
                    screenName,
                    count,
                    includeRTs,
                    sinceMessageId
                )
                .Select(m => (TwitterMessage)m)
                .ToList();

            foreach (TwitterMessage tweet in basicTweets)
                Console.WriteLine(tweet.Text + "\n\n");


            ////semi custom
            //List<TwitterMessage> semiCustomTweets = UserTimeline<TwitterConfig>.GetTweets<TwitterMessage, TwitterUser>
            //    (
            //        screenName,
            //        count,
            //        includeRTs,
            //        sinceMessageId
            //    );

            //foreach (TwitterMessage tweet in semiCustomTweets)
            //    Console.WriteLine(tweet.Text + "\n\n");


            ////fully custom
            //List<TwitterMessage> customTweets = UserTimeline<TwitterConfig>.GetTweets<TwitterMessage, TwitterUser, TwitterMedia, TwitterMediaSize>
            //    (
            //        screenName,
            //        count,
            //        includeRTs,
            //        sinceMessageId
            //    );

            //foreach (TwitterMessage tweet in customTweets)
            //    Console.WriteLine(tweet.Text + "\n\n");


            ////posting
            //string message = "hello world, from the code's and stuff!";
            //string replyToMessageId = "1234";

            //UserTimeline<TwitterConfig>.PostUpdate(message);
            ////UserTimeline<TwitterConfig>.PostUpdate(message, replyToMessageId);

            Console.ReadKey();
        }
    }
}
